package com.lyb.controller;

import com.lyb.pojo.Category;
import com.lyb.service.CategoryService;
import com.lyb.utils.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("category")
@CrossOrigin
@Tag(name = "类别接口文档")
public class CategoryController {
    @Autowired
    private CategoryService service;

    @GetMapping("list")
    public Result queryList(){
        Result result = service.queryList();
        return result;
    }

    @GetMapping()
    public Result queryByPage(@Parameter(description = "页数，默认1") @RequestParam(defaultValue = "1") Integer page,
                              @Parameter(description = "数量，默认5")@RequestParam(defaultValue = "5") Integer size, String keyword){

        Result result = service.queryByPage(page,size,keyword);
        return result;
    }

    @GetMapping("{id}")
    public Result queryById(@PathVariable Integer id){
       Result result = service.queryById(id);
        return result;
    }

    @PostMapping
    public Result saveCategory(@RequestBody Category category){
        Result result = service.saveCategory(category);
        return result;
    }

    @PutMapping
    public Result updateCategory(@RequestBody Category category){
        Result result = service.updateCategory(category);
        return result;
    }

    @DeleteMapping("{id}")
    public Result deleteCategory(@PathVariable Integer id){
        Result result = service.deleteCategory(id);
        return result;
    }
}
